<?php
/**
 *
 * @group_name =
 *
 * @author Master
 *
 * @api UpdataPassWord
 *
 * @time 2020/6/5 - 1:02
 *
 */

namespace app\api\validate;


use think\Db;
use think\Validate;

class UpdataPassWord extends Validate
{
    protected $rule = [
        "id" =>'require',
        'oldpassword' =>'require|check_oldpassword:oldpassword',
        'password' => 'require',

    ];

    protected $message = [
        'id.require' => '用户编号不能为空',
        'oldpassword.require' => '原不能为空',
        'password.require' => '新密码不能为空',
    ];

    public function check_oldpassword($data){
        $user_id = input("id");
        $password = input("password");
        $result = Db::name("account")->where(["data_state" => 1,"id" =>$user_id ])->find();
        if ($result){
            if ($result["password"] == password_md5($data)){
                if (password_md5($password) ==  password_md5($data)){
                    return "新密码与原密码不能相同";
                }else{
                    return true;
                }
            }else{
                return "原密码错误";
            }
        }else{
            return "当前用户不存在";
        }

    }
}